//
//  ViewController.m
//  JKXML
//
//  Created by 王冲 on 2019/1/25.
//  Copyright © 2019年 JK科技有限公司. All rights reserved.
//

#import "ViewController.h"
#import "VideoModel.h"
#import "JKXML.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
}






-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self demo1];
    
}

#pragma mark  解析：本地测试
-(void)demo1{
    
    NSLog(@"%@",NSStringFromSelector(_cmd));
    
    NSString *path =[[NSString alloc]initWithString:[[NSBundle mainBundle]pathForResource:@"video"ofType:@"xml"]];
    NSData *data = [[NSData alloc]initWithContentsOfFile:path];
    
    NSArray *array = [[JKXML new]jk_parseXMLData:data];
    
    NSLog(@"解析后的数组=%@",array);

}

#pragma mark plist 解析：网络测试
-(void)demo2{
    
    // 1.编码  plist 很少用于传输网络数据，在苹果端用的比较多
    NSString *urlStr = [@"http://localhost/video.xml" stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    NSURL *url = [NSURL URLWithString:urlStr];
    
    // 2.request
    NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
    
    // 3.网络请求
    [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc]init] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        
        
        NSArray *array = [[JKXML new]jk_parseXMLData:data];
        
        NSLog(@"解析后的数组=%@",array);

        
    }];
}


@end
